#define _CRT_SECURE_NO_WARNINGS
struct TreeNode* reConstructBinaryTree(int* preOrder, int preOrderLen, int* vinOrder, int vinOrderLen) {
    // write code here
    if (preOrderLen == 0) {
        return NULL;
    }

    int precur = 0, vincur = 0, top = 0;
    bool flag = false;
    struct TreeNode* stack[2000];

    struct TreeNode* root, * now;
    root = (struct TreeNode*)malloc(sizeof(struct TreeNode));
    root->val = preOrder[precur++];

    stack[0] = root;

    while (precur < preOrderLen) {
        while (stack[top]->val == vinOrder[vincur]) {
            vincur++;
            now = stack[top--];
            flag = true;
        }
        struct TreeNode* temp;
        temp = (struct TreeNode*)malloc(sizeof(struct TreeNode));
        temp->val = preOrder[precur++];

        if (flag) {
            now->right = temp;
            flag = false;
        }
        else {
            stack[top]->left = temp;
        }

        top++;
        stack[top] = temp;
    }

    return root;
}